package br.ufcg.edu.routers.config;

import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;

import junit.framework.TestCase;

public class RoutersParserTest extends TestCase {
	
	public void test1() throws IOException {
		String configFile = "unitTests/files/roteador1.config";
		
		RoutersParser parser = new RoutersParser(2, Arrays.asList(3), configFile);
		assertEquals("{3=127.0.0.4:25003}", parser.getNeighbourRoutersMap().toString());
		assertEquals("127.0.0.2:25002", parser.getRouterAddressAndPort().toString());
		assertEquals("[1, 2, 3, 4]", parser.getRoutersId().toString());
		
		parser = new RoutersParser(1, Arrays.asList(2, 3), configFile);
		assertEquals("{2=127.0.0.2:25002, 3=127.0.0.4:25003}", parser.getNeighbourRoutersMap().toString());
		assertEquals("127.0.0.1:25001", parser.getRouterAddressAndPort().toString());
		assertEquals("[1, 2, 3, 4]", parser.getRoutersId().toString());
		
		parser = new RoutersParser(1, Arrays.asList(2, 3, 4), configFile);
		assertEquals("{2=127.0.0.2:25002, 3=127.0.0.4:25003, 4=127.0.0.3:25004}", parser.getNeighbourRoutersMap().toString());
		assertEquals("127.0.0.1:25001", parser.getRouterAddressAndPort().toString());
		assertEquals("[1, 2, 3, 4]", parser.getRoutersId().toString());
		
	}
	
	public void test2() throws IOException {
		String configFile = "unitTests/files/roteador2.config";
		RoutersParser parser = new RoutersParser(1, Arrays.asList(2), configFile);
		assertEquals("{2=127.0.0.1:25002}", parser.getNeighbourRoutersMap().toString());
		assertEquals("127.0.0.1:25001", parser.getRouterAddressAndPort().toString());
		assertEquals("[1, 2]", parser.getRoutersId().toString());

		parser = new RoutersParser(1, new LinkedList<Integer>(), configFile);
		assertEquals("{}", parser.getNeighbourRoutersMap().toString());
		assertEquals("127.0.0.1:25001", parser.getRouterAddressAndPort().toString());
		assertEquals("[1, 2]", parser.getRoutersId().toString());
		
		parser = new RoutersParser(2, new LinkedList<Integer>(), configFile);
		assertEquals("{}", parser.getNeighbourRoutersMap().toString());
		assertEquals("127.0.0.1:25002", parser.getRouterAddressAndPort().toString());
		assertEquals("[1, 2]", parser.getRoutersId().toString());
		
		parser = new RoutersParser(2, Arrays.asList(1), configFile);
		assertEquals("{1=127.0.0.1:25001}", parser.getNeighbourRoutersMap().toString());
		assertEquals("127.0.0.1:25002", parser.getRouterAddressAndPort().toString());
		assertEquals("[1, 2]", parser.getRoutersId().toString());
	}

}
